package com.xiaomengkuan.plugin.controller;

import com.aliyuncs.exceptions.ClientException;
import com.xiaomengkuan.common.util.R;
import com.xiaomengkuan.plugin.service.SmsService;
import io.swagger.annotations.Api;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Faraj Mujey
 * -- Creation Time: 2021-01-13 10:09 下午, File Encoding: utf8 --
 */
@RestController
@Api
@RequestMapping("/plugin/sms")
public class SmsController {
    @Resource
    private SmsService smsService;

    @GetMapping("/sendMessage/{phone}")
    public R sendMessage(@PathVariable("phone") String phone) throws ClientException {
        String code = smsService.sendMessage(phone);
        if (!StringUtils.isEmpty(code)){
            return R.ok().put("code",code);
        } else {
            return R.err();
        }
    }
}
